/*
Test the defrule construct with the Account class. 
*/

(deftemplate person 
		(slot memberName)
		(slot age)
)

(watch all)

(reset)

(defrule welcome-kids
        "Give a special greeting to young children"
        (person {age >= 3})
        =>
        (printout t "Hello, little one!" crlf)
)

( defrule welcome-teenagers
		"special rule for teenagers"
		?p <- (person {age > 12 && age < 20}  (memberName ?name))
		=>
		(printout t "Hello " ?name " you are " ?p.age " years old." crlf)
)

( defrule teenagers-and-roy
		"special rule for teenagers called Roy"
		?p <- (person 
				{ (age > 12 && age < 20) && (memberName == Roy)
				}
			  )
		=>
		(printout t "Special welcome to " ?p.memberName " who is " ?p.age " years old." crlf)
)

( defrule same-name-persons
		"Teenagers with the same name should get detected"
		?person1 <- (person)
		?person2 <- (person {(age == person1.age) && (memberName <> person1.memberName) })
		=>
		(printout t "Found two people of the same age - " ?person1.age " who are called " ?person1.memberName " and " ?person2.memberName crlf)
)

(assert (person (age 7)))

(assert (person (memberName Roy) (age 17) ) )
(assert (person (memberName Roma) (age 17) ) )

(run)